home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Completions Source / Pipes / PipeOutput.h < prev    next >
Encoding:
Text File  |  1998-06-19  |  1.8 KB  |  92 lines  |  [TEXT/CWIE]

  1. // PipeOutput.h
  2.  
  3. #ifndef PipeOutput_h
  4. #define PipeOutput_h
  5.  
  6. #ifndef ConstBufferMaster_h
  7. #include "ConstBufferMaster.h"
  8. #endif
  9. #ifndef Sleeper_h
  10. #include "Sleeper.h"
  11. #endif
  12. #ifndef PipePacket_h
  13. #include "PipePacket.h"
  14. #endif
  15. #ifndef TaskSequencer_h
  16. #include "TaskSequencer.h"
  17. #endif
  18.  
  19. class TeeBase;
  20.  
  21. class PipeOutput
  22.   {
  23.     friend class PipeOutputMaster;
  24.     
  25.     private:
  26.         ConstBufferMaster buffer;
  27.         ConstData ring;
  28.         TeeBase *pipe;
  29.         
  30.         PipePacket entering;
  31.         PipePacket exiting;
  32.         
  33.         Sleeper sleep;
  34.         uint32 acceptLength;
  35.         
  36.         bool flushing;
  37.         
  38.         TaskSequencer<PipeOutput> sequence;
  39.         typedef TaskStep<PipeOutput> Step;
  40.  
  41.         PipeOutput();
  42.         void Initialize( ConstData, TeeBase& );
  43.         void Reset();
  44.  
  45.         void PushIn( PipePacket );
  46.         const PipePacket& Leaving() const        { return exiting; }
  47.         void PullOut( PipePacket out )            { exiting -= out; }
  48.         uint32 Audit() const;
  49.         const uint8 *ExitingStart() const;
  50.         const uint8 *EnteringEnd() const;
  51.         
  52.         void MoveBuffer();
  53.  
  54.         Step DoPass( bool dying, DeferredTaskTime );
  55.         Step TryAccept( bool dying, DeferredTaskTime );
  56.         Step DoAcknowledgeFlush( bool dying, DeferredTaskTime );
  57.         
  58.     public:
  59.         ConstBuffer& Buffer()                        { return buffer; }
  60.         const ConstBuffer& Buffer() const        { return buffer; }
  61.         
  62.         uint32 PotentialLength() const;
  63.         uint32 RingLength() const                    { return ring.Length(); }
  64.  
  65.         uint32 LargestAcceptSize() const;
  66.         uint32 ReasonableAcceptSize() const;
  67.         uint32 ReasonablePassSize() const;
  68.  
  69.         bool Flushing() const                        { return flushing; }
  70.         
  71.         Task *Pass();
  72.         Task *Accept( uint32 requiredSize );
  73.         Task *AcknowledgeFlush();
  74.   };
  75.  
  76. class PipeOutputMaster: public PipeOutput
  77.   {
  78.     public:
  79.         PipeOutputMaster()        {}        // To keep CW Pro 3 happy
  80.         
  81.         PipeOutput::Initialize;
  82.         PipeOutput::Reset;
  83.         PipeOutput::PushIn;
  84.         PipeOutput::Leaving;
  85.         PipeOutput::PullOut;
  86.         PipeOutput::Audit;
  87.         PipeOutput::ExitingStart;
  88.         PipeOutput::EnteringEnd;
  89.   };
  90.  
  91. #endif
  92.